feat: Route binary operations through the shader generator - #2822
Conversation
|
pkg.pr.new packages benchmark commit |
b5d746f to
077d022
Compare
Resolution Time Benchmark---
config:
themeVariables:
xyChart:
plotColorPalette: "#E63946, #3B82F6, #059669"
---
xychart
title "Random Branching (🔴 PR | 🔵 main | 🟢 release)"
x-axis "max depth" [1, 2, 3, 4, 5, 6, 7, 8]
y-axis "time (ms)"
line [0.97, 1.97, 4.32, 7.06, 8.00, 12.43, 22.99, 26.56]
line [0.93, 2.00, 4.34, 7.22, 7.57, 12.45, 23.46, 26.07]
line [0.94, 2.09, 4.70, 6.90, 8.44, 13.72, 24.29, 24.30]
---
config:
themeVariables:
xyChart:
plotColorPalette: "#E63946, #3B82F6, #059669"
---
xychart
title "Linear Recursion (🔴 PR | 🔵 main | 🟢 release)"
x-axis "max depth" [1, 2, 3, 4, 5, 6, 7, 8]
y-axis "time (ms)"
line [0.35, 0.56, 0.73, 0.87, 1.12, 1.24, 1.49, 1.65]
line [0.35, 0.47, 0.69, 0.79, 1.16, 1.20, 1.41, 1.57]
line [0.33, 0.54, 0.75, 0.96, 1.27, 1.33, 1.65, 1.69]
---
config:
themeVariables:
xyChart:
plotColorPalette: "#E63946, #3B82F6, #059669"
---
xychart
title "Full Tree (🔴 PR | 🔵 main | 🟢 release)"
x-axis "max depth" [1, 2, 3, 4, 5, 6, 7, 8]
y-axis "time (ms)"
line [0.90, 2.15, 4.14, 7.08, 12.49, 27.43, 56.80, 116.18]
line [0.81, 2.21, 4.49, 6.98, 13.10, 27.09, 56.71, 117.59]
line [1.07, 2.10, 4.28, 8.03, 14.22, 28.61, 61.53, 126.47]
|
Bundle size comparison (
|
| 🟢 Decreased (max -0.25%) | ➖ Unchanged | 🔴 Increased (max 2.79%) | ❔ Unknown |
|---|---|---|---|
| 6 | 130 | 187 | 1 |
import * as ... in PR vs import * as ... in target (did bundle size increase?):
| Test | tsdown |
|---|---|
| std_isBeingTranspiled.ts | 15.71 kB ( |
| std_getTargetShaderLanguage.ts | 15.77 kB ( |
| STATIC_std.ts | 110.10 kB ( |
| std_getShaderStage.ts | 15.76 kB |
import { ... } in PR vs import * as ... in PR (is the library tree-Shakeable?):
| Test | tsdown |
|---|---|
| tgpu_init.ts | 270.69 kB ( |
| tgpu_initFromDevice.ts | 270.15 kB ( |
| tgpu_resolve.ts | 170.93 kB ( |
| tgpu_resolveWithContext.ts | 170.87 kB ( |
| tgpu_bindGroupLayout.ts | 73.93 kB ( |
| tgpu_mutableAccessor.ts | 68.66 kB ( |
| tgpu_accessor.ts | 68.66 kB ( |
| tgpu_privateVar.ts | 67.35 kB ( |
| tgpu_workgroupVar.ts | 67.35 kB ( |
| tgpu_const.ts | 66.77 kB ( |
| tgpu_lazy.ts | 66.56 kB ( |
| tgpu_fragmentFn.ts | 38.92 kB ( |
| tgpu_fn.ts | 38.87 kB ( |
| tgpu_vertexFn.ts | 38.74 kB ( |
| tgpu_computeFn.ts | 38.44 kB ( |
| tgpu_vertexLayout.ts | 27.57 kB ( |
| tgpu_comptime.ts | 15.18 kB ( |
| tgpu_unroll.ts | 1.75 kB ( |
| tgpu_slot.ts | 1.70 kB ( |
If you wish to run a comparison for other, slower bundlers, run the 'Tree-shake test' from the GitHub Actions menu.
There was a problem hiding this comment.
ℹ️ Minor suggestions only — one small typo in an error message.
Reviewed changes
emitBinaryOproute — AddedemitBinaryOpplus theBinaryOperatorunion to theShaderGeneratorinterface andWgslGenerator, and rewired+ - * / % << >>instd/operators.tsand the binary-expression emitter through it (replacing inlinestitchand the old parenthesization block).- Method renames — Renamed the unstable
ShaderGeneratormethodscall→emitCallandtypeAnnotation→emitTypeAnnotationacrossWgslGenerator,GlslGenerator,internal.ts,resolutionCtx.ts, and every std codegen call site. All callers were updated. _callShelllessextraction — Factored the shellless-call lowering out of_expressioninto a reusable protectedWgslGenerator._callShellless, and reused it fromGlslGenerator.emitBinaryOpto translate floating-point%into aremaindershell helper (GLSL ES has no float%), leaving non-float%on thesuperpath.
The parenthesization and operator-mapping behavior is preserved for WGSL, so existing WGSL snapshots should be unaffected.
ℹ️ Nitpicks
packages/typegpu-gl/src/glslGenerator.ts:430— error message has a doubled(type:prefix on the RHS operand.- The
%→remainderpath in the new test only covers scalarf32;vec2f/3f/4foperands hit the same branch but aren't exercised.
DeepSeek Flash (free via Pullfrog for OSS) | 𝕏
077d022 to
728fda6
Compare
728fda6 to
74bc6ff
Compare
There was a problem hiding this comment.
Pull request overview
This PR centralizes emission of binary operations (and related helpers like function calls/type annotations) behind the ShaderGenerator interface so language backends (notably GLSL) can customize operator lowering while reusing the same TGSL resolution pipeline.
Changes:
- Add
emitBinaryOptoShaderGeneratorand route TGSL binary/assignment/logical operator emission through it. - Rename
typeAnnotation/calltoemitTypeAnnotation/emitCalland update stdlib + resolution code to use the new API. - Extend the GLSL generator to lower floating-point
%to a generatedremainderhelper, with a new regression test.
Reviewed changes
Copilot reviewed 12 out of 12 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| packages/typegpu/src/tgsl/wgslGenerator.ts | Adds _callShellless, routes binary ops via emitBinaryOp, renames generator emission helpers. |
| packages/typegpu/src/tgsl/shellless.ts | Makes ShelllessRepository.get accept readonly snippet arrays. |
| packages/typegpu/src/tgsl/shaderGenerator.ts | Extends generator interface with emitBinaryOp and renames emission methods. |
| packages/typegpu/src/std/operators.ts | Routes arithmetic/shift operator codegen via ctx.gen.emitBinaryOp (and generator-driven instantiation). |
| packages/typegpu/src/std/numeric.ts | Updates built-in call emission to emitCall. |
| packages/typegpu/src/std/boolean.ts | Updates built-in call emission to emitCall. |
| packages/typegpu/src/std/bitcast.ts | Updates built-in call emission to emitCall. |
| packages/typegpu/src/std/array.ts | Updates built-in call emission to emitCall. |
| packages/typegpu/src/resolutionCtx.ts | Updates schema-to-type annotation emission to emitTypeAnnotation. |
| packages/typegpu/src/internal.ts | Re-exports BinaryOperator from internal API surface. |
| packages/typegpu-gl/tests/glslGenerator.test.ts | Adds test ensuring float % becomes a remainder() call in GLSL output. |
| packages/typegpu-gl/src/glslGenerator.ts | Implements GLSL-specific % lowering via a shellless remainder helper and updates renamed methods. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
e4d25cd to
a1ffa8d
Compare
a1ffa8d to
141d651
Compare
141d651 to
f027104
Compare
f027104 to
cc0f470
Compare
cc0f470 to
26834db
Compare
b52e007 to
eae3134
Compare
|
Run failed. View the logs →
|
eae3134 to
4050ec3
Compare
4050ec3 to
3a3e613
Compare
Potential fix for pull request finding Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
3a3e613 to
94707c7
Compare

No description provided.